package team2.arsystem.GUI;

import team2.arsystem.Controller.ApplicationController;
import team2.arsystem.Utilities.CommandConstants;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class SetCurrency extends Activity{
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.setcurrency);
        
        Button okButton = (Button)findViewById(R.id.buttonOKSetCurrency);
        Button cancelButton = (Button)findViewById(R.id.buttonCancelSetCurrency);
        final Spinner currencySpinner = (Spinner)findViewById(R.id.spinnerCurrency);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.currency_array, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		currencySpinner.setAdapter(adapter);
        
        okButton.setOnClickListener(new OnClickListener() {
			
        	public void onClick(View v) {
        		
        		String[] currencySelected = new String[1];
        		currencySelected[0] = currencySpinner.getSelectedItem().toString(); 
        		if((ApplicationController.getApplicationController().passCommand(CommandConstants.setCurrency,currencySelected)))
	        	{
	        		try
	        		{
	        			Dialog dialogOK = new Dialog(SetCurrency.this);
	        			dialogOK.setContentView(R.layout.popupbox);
	        			dialogOK.setTitle("Account Reminder System");
	        			
	        		        			
	        			TextView dialogText = (TextView)dialogOK.findViewById(R.id.textViewDialogMessage);
	        			dialogText.setText("The currency mode was set successfully");
	        			
	        			
	                    Button button = (Button) dialogOK.findViewById(R.id.buttonDialogOK);
	                   
	                    button.setOnClickListener(new OnClickListener() {
	                   
	                        public void onClick(View v) {
	                        	
	                        	try
	                        	{
	                        	 Class menuScreen = Class.forName("team2.arsystem.GUI."+"Settings");
	                    		 Intent myIntent = new Intent(SetCurrency.this,menuScreen);
	                    		 startActivity(myIntent);
	                        	}
	                        	catch(Exception e){
	                    			 e.printStackTrace();
	                    		 }
	                    		 
	                        }
	                    });
	        		    
	            		 
	                    dialogOK.show();
	        		}
	        		catch(Exception e)
	        		{
	        			
	        		}
	        	}
        		
        	}
        	
        });
        
        /* If Cancel button is clicked, take the user to the menu screen*/
		cancelButton.setOnClickListener(new OnClickListener() {
				
	        public void onClick(View v) {
	        		
	          try
	          {
	           	 Class menuScreen = Class.forName("team2.arsystem.GUI."+"Settings");
	          	 Intent myIntent = new Intent(SetCurrency.this,menuScreen);
	          	 startActivity(myIntent);
	       	  }
	                   
	          catch(Exception e)
	          {
	              e.printStackTrace();
	          }
	                    		 
	       }
	        	
	     });
        
	}

}
